//
//  MKReaderPageModel.swift
//  Fanmugua
//
//  Created by MK on 2021/3/27.
//  Copyright © 2021 taolang. All rights reserved.
//

import UIKit

enum ReaderPageCellType: Int{
    case content = 0
    case comment = 1;   //评论
    case authorWord = 2;    //作者的话
    case solfAd = 3;    //信息流广告
    case flyleaf = 4;    //扉页
    
    case others = 5;   //以上集合
}

@objc class MKReaderPageModel: NSObject, NSCoding {

    @objc var content:NSAttributedString!   //当前页内容
    var range:NSRange!                      //当前页范围
    @objc var page:NSNumber!                //当前页序号
    var contentSize:CGSize!                 //当前内容Size
    var type:ReaderPageCellType = .content
    var lastPage:Bool = false
    var adView:UIView?
        
    @objc func getContentSize() -> CGSize{
        return contentSize
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init()
        content = aDecoder.decodeObject(forKey: "content") as? NSAttributedString
        range = aDecoder.decodeObject(forKey: "range") as? NSRange
        page = aDecoder.decodeObject(forKey: "page") as? NSNumber
        contentSize = aDecoder.decodeObject(forKey: "contentSize") as? CGSize
        type = aDecoder.decodeObject(forKey: "type") as! ReaderPageCellType
        lastPage = aDecoder.decodeObject(forKey: "lastPage") as! Bool
    }
    
    func encode(with aCoder: NSCoder) {
        aCoder.encode(content, forKey: "content")
        aCoder.encode(range, forKey: "range")
        aCoder.encode(page, forKey: "page")
        aCoder.encode(contentSize, forKey: "contentSize")
        aCoder.encode(type, forKey: "type")
        aCoder.encode(lastPage, forKey: "lastPage")
    }
    
    init(_ dict:Any? = nil) {
        super.init()
        if dict != nil { setValuesForKeys(dict as! [String : Any]) }
    }
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) { }
}
